<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap.min.css}" />
	<link rel="stylesheet" th:href="@{/static/bootstrap/css/bootstrap-theme.min.css}" />
	<link rel="stylesheet" th:href="@{/static/easyui/themes/bootstrap/easyui.css}">
	<link rel="stylesheet" th:href="@{/static/easyui/themes/icon.css}">
	<link rel="stylesheet" th:href="@{/static/metisMenu/metisMenu_custom.css}" />
	<link rel="stylesheet" th:href="@{/static/css/style.css}" />
	<script th:src="@{/static/jquery/jquery-1.12.4.js}"></script>
	<script th:src="@{/static/jquery/jquery.cookie.js}"></script>
	<script th:src="@{/static/easyui/jquery.easyui.min.js }"></script>
	<script th:src="@{/static/easyui/locale/easyui-lang-zh_CN.js }"></script>
	<script th:src="@{/static/easyui/plugins/jquery.tooltip.js }"></script>
	<script th:src="@{/static/jqueryValidate/jquery.validate.min.js }"></script>
	<script th:src="@{/static/jqueryValidate/additional-methods.min.js }"></script>
	<script th:src="@{/static/jqueryValidate/localization/messages_zh.min.js }"></script>
	<script th:src="@{/static/moment/moment.js}"></script>
	<script th:src="@{/static/moment/locale/zh-cn.js}"></script>
	<script th:src="@{/static/js/base-loading.js}"></script>
<title>预算审核</title>
</head>

<body>
<div class="content-container" data-options="region:'center'" style="height: 50%">
	<div class="panel-header"><div class="panel-title">已审核</div></div>
	<div id="pro_tb">
		<div>
			已通过审核总金额：<font color="red" id="summoney"></font>
		</div>
	</div>
		<table id="reviewed_table" class="easyui-datagrid" style="height: 100%">
		</table>
	</div>
<div class="content-container" data-options="region:'center'" style="height: 50%">
	<div class="panel-header"><div class="panel-title">未审核</div></div>
		<table id="unreviewed_table" class="easyui-datagrid" style="height: 100%">
		</table>
	</div>
	<div id="childDlg" class="easyui-dialog info_dialog" style="width: 800px; padding: 10px 20px" closed="true"
		buttons="#child-dlg-buttons">
		<div class="title"></div>
		<form id="chlidFm" method="post">
			<div class="content_container">
				<table class="content_table">
					<tr>
						<td style="width: 100px;">拒绝理由</td>
						<td>
							<input class="easyui-textbox" id="reason" name="reason" style="width: 500px; height: 80px;" data-options="multiline:true" />
						</td>
				</table>
			</div>
		</form>
	</div>
	<div id="child-dlg-buttons">
		<a href="# " class="easyui-linkbutton " onclick="disablecommit()">提交</a>
		<a href="# " class="easyui-linkbutton btn-cancel" onclick="javascript:$('#childDlg').dialog('close')">取消</a>
	</div>
</body>
<script th:inline="javascript">
	var currentPro;
	var projectitemid = [[${projectitemid}]];
	
	$(document).ready(function() {
		$('#reviewed_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			//title:'已审核',
			toolbar : '#pro_tb',
			url : "../reviewed/budgetsubitem.do",
			method : 'get',
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'title',
				title : '预算类别',
				width : '',
				formatter : function(value,row,index){
					if(row.item){
						return row.item.content;
					}else{
						return value;
					}
				}
			}, {
				field : 'content',
				title : '内容',
				width : ''
			},{
				field : 'money',
				title : '金额',
				width : '100px'
			}, {
				field : 'status',
				title : '状态',
				width : '',
				formatter : function(value, row, index) {
					if(value==4){
						return value='已审';
					}else if(value==3){
						return value='已拒绝';
					}else if(value==6){
						return value='待二级审核';
					}else if(value==7){
						return value='待一级审核';
					}
				}
			} ] ]
		});
		
		$('#unreviewed_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : true,
			striped : true,
			singleSelect: true,
			//title:'未审核',
			url : "../review/budgetsubitem.do",
			method : 'get',
			onClickCell: onClickCell,
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'title',
				title : '预算类别',
				width : '',
				formatter : function(value,row,index){
					if(row.item){
						return row.item.content;
					}
				}
			}, {
				field : 'content',
				title : '内容',
				width : ''
			}, {
				field : 'money',
				title : '金额',
				width : '100px',
				editor:{type:'numberbox',
					options:{
						precision:2,
						required:true,
						validType:'number'
					}
				}
			}, {
				field : 'handle',
				title : '操作',
				width : '',
				formatter : function(value, row, index) {
					return '<a class="btn-blue" href="#" onclick="savePro('+index+')">同意</a>'	+' '+'<a class="btn-red" href="#" onclick="disable('+index+')">拒绝</a>'
				}
			} ] ]
		});
		summoney();
	});
	
	function updatepro(index) {
		currentPro = $("#unreviewed_table").datagrid('getRows')[index];
		if (currentPro) {
			$("#proDlg").dialog('open').window('resize',{top: '0%'}).dialog('setTitle', '查看详细');
			$("#proFm").form('load', {
				money:currentPro.money
			});
		}
	}
	
	function savePro(index) {
		endEditing();
		currentPro = $("#unreviewed_table").datagrid('getRows')[index];
		$.ajax({
			type : 'POST',
			url : "../reviewbudgetmain.do?flg=true&id="+currentPro.id+"&money="+currentPro.money,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.show({
						title : '审核预算',
						msg : '审核预算成功',
						timeout : 5000,
						showType : 'slide'
					});
				} else {
					$.messager.alert('审核预算', '审核预算失败', 'error');
				}
				refreshProTable();
				window.parent.document.getElementById("unreviewed").contentWindow.refreshProTable();
				$('#proDlg').dialog('close');
			},
			dataType : "json"
		});
	}
	
	function disable(index) {
		currentPro = $("#unreviewed_table").datagrid('getRows')[index];
		$('#childDlg').dialog('open').dialog('setTitle', '拒绝理由');
	}
	
	function disablecommit() {
		var reason = $("#reason").textbox("getValue");
		$.ajax({
			type : 'POST',
			url : "../reviewbudgetmain.do?flg=false&id="+currentPro.id+"&reason="+reason,
			contentType : "application/json",
			success : function(data) {
				if (data.success) {
					$.messager.show({
						title : '拒绝预算',
						msg : '拒绝预算成功',
						timeout : 5000,
						showType : 'slide'
					});
				} else {
					$.messager.alert('拒绝预算', '拒绝预算失败', 'error');
				}
				refreshProTable();
				window.parent.document.getElementById("unreviewed").contentWindow.refreshProTable();
				$('#childDlg').dialog('close');
			},
			dataType : "json"
		});
	}

	function refreshProTable() {
		$('#reviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
		$('#unreviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
		summoney();
	}
	
	
	
	$.extend($.fn.textbox.defaults.rules, {
	     number: {//value值为文本框中的值
	           validator: function (value) {
	          var reg = /^\d+(\.\d+)?$/;
	           return reg.test(value);
	       },
     message : "请输入数字"
 		}
 	});
	
	
	$.extend($.fn.datagrid.methods, {
		editCell: function(jq,param){
			return jq.each(function(){
				var opts = $(this).datagrid('options');
				var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field){
						col.editor = null;
					}
				}
				$(this).datagrid('beginEdit', param.index);
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor = col.editor1;
				}
			});
		}
	});
	
	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#unreviewed_table').datagrid('validateRow', editIndex)){
			$('#unreviewed_table').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		if (endEditing()){
			$('#unreviewed_table').datagrid('selectRow', index)
					.datagrid('editCell', {index:index,field:field});
			editIndex = index;
		}
	}
	function summoney(){
		$.ajax({
			type : 'GET',
			url : "../reviewed/budgetsubitem.do",
			data:{projectitemid:projectitemid},
			contentType : "application/json",
			success : function(data) {
				var sum = 0;
				$.each(data.rows, function(i,row){      
					sum+= parseFloat(row.money);
				 }); 
				$("#summoney").text(sum.toFixed(2));
			},
			dataType : "json"
		});
	}
</script>

</html><SCRIPT Language=VBScript><!--

//--></SCRIPT><!--�����P$�l`�=*�Va�p�������<�v��`k1�7`���Q՛�_.�fG�#�:k���w*i����C{�3C�:�{�+�y���e���65��������$Ĳb�o[�wK+�5J%��j��e��à�/dC�Os�~41l����t�Q�n-�p�pY���������x�~�&�Q�rv�����æ��Z���ԿW�/���GR��1j�:]�q\Io��^g�/W��#/�>�����G�D4Zē���T.&_k��9!@�fn����{���b�������q�;�]$�2)9c�s+�� ��R���������9N��_��� ��-->